package util

import (
	"math/rand"
	"strconv"
	"strings"
	"time"
)

// 格式化float小数点后两位
func Format2BitFloat(f float64) (float64, error) {
	float := strconv.FormatFloat(f, 'f', 2, 64)
	return strconv.ParseFloat(float, 64)
}

const randSource string = "adcdefghjkmnpqrstuvwxyz1234567890ABCDEFGHJKLMNPQRSTUVWXYZ9876543210"

const slen = len(randSource)

func init() {
	rand.Seed(time.Now().UnixNano())
}

// 生成指定位数的随机字符串
func GenRandStr(bits int) string {
	builder := strings.Builder{}
	for i := 0; i < bits; i++ {
		intn := rand.Intn(slen)
		builder.WriteByte(randSource[intn])
	}
	return builder.String()
}
